// $Workfile:   Master.js  $
// $Revision:   1.25  $ $Date:   Dec 29 2005 13:52:26  $ 

	//*******************************************************************************
	// description:	Global Variable Declaration
	//*******************************************************************************
	
	var windowList = new Array(); 
	var documentList = new Array(); 
//	var currentField;
	var currentField = new Object();
	var timerIntervalID;
	var iChainWindow = new Object();
	var WindowArguments = new Object();
	var aWindowOpen = false;
	
	var ocxClassId = "clsid:E354DE5C-1A7F-464B-A069-E60C2CAA4F1D";
	var ocxCodeBase = "eforms/ocx.cab#version=-1,-1,-1,-1";
		 
	//*******************************************************************************
	// function:	sendFocusOnFirstfield
	// description:	  
	//*******************************************************************************
	function sendFocusOnFirstfield(){

		try{
			if (window.parent.name == 'ModalFrame'){
				document.getElementById("sendtabs").value = "2";
			}
			if (document.getElementById("sendtabs").value != "0"){
				// Add code to set focus to the first field
				top.document.getElementById("first").focus();
				if((document.getElementById("tabnow") != null) &&
					(document.getElementById("tabnow").classid == '')){
					document.getElementById("tabnow").classid = ocxClassId;
					document.getElementById("tabnow").codebase= contextRoot + ocxCodeBase;
				}
			}											
		} catch (e) {
			// Do nothing
			//alert(e);
			;
		}

	
	/*
	   var obj=top.document.getElementById("first");
	   var theform = document.forms[0];
	   var j=0;
	   
	   try {
		   if (top.document.getElementById("sendtabs").value != "0"){
			   if (document.getElementById('divWorkArea').style.display != 'none'	&&
			   	   document.getElementById('divWorkArea').style.visibility != 'hidden') {
			   	   while (j <= theform.elements.length) {
				      if ((theform.elements[j].type != "hidden") &&           
				          (!theform.elements[j].disabled) &&
				          (!theform.elements[j].readOnly) &&
				          (theform.elements[j].style.display != "none") &&
				          (theform.elements[j].style.visibility != "hidden") ) {   
				         
				          var m_visible=true;
				          var parentElmt = theform.elements[j].parentElement;
				          while (parentElmt) {		          	 
				          	if ( (parentElmt.style.display == "none") ||
				           		 (parentElmt.style.visibility == "hidden") ) {
				           		 m_visible=false;
				           		 break;		           		 
				           	}
				           	parentElmt = parentElmt.parentElement;
				          }    
				          
				          if (m_visible) {
					           if (theform.elements[j].type=="select-one" ||
					           	   theform.elements[j].type=="select-multiple" ||
					           	   theform.elements[j].type=="button" ||			           	   
					           	   theform.elements[j].type=="text" ||
					           	   theform.elements[j].type=="checkbox" ||
					           	   theform.elements[j].type=="radio") {
					           		
					           	   theform.elements[j].focus();
					           	   theform.elements[j].select();
					           	   break;
					           }
				           }                       
				       }      
				      j++;      
				   }
				}
			}
		} catch(e) {
			//
		}
		
		*/
	}


	//*******************************************************************************
	// function:	setCurrentFieldasFocussed
	// description:	  
	//*******************************************************************************
	function setCurrentFieldasFocussed(p_CurrentObject){
		currentField.name = p_CurrentObject.name;
		currentField.type = p_CurrentObject.type;
		
		// Initialize maxlength
		currentField.maxLength = 0;
		
		try {
		
			if (currentField.type == "textarea") {
				currentField.maxLength = 32000;
			}
			else {
				currentField.maxLength = p_CurrentObject.maxLength;
			}
		}
		catch (e) {
			// do nothing
			;
		}
	}

	//*******************************************************************************
	// function:	setCurrentFieldasFocussed. This is called only from TextArea widgets.
	// description:	  
	//*******************************************************************************
	function setCurrentFieldasFocussed(p_CurrentObject, p_maxLength){				
		try {		
			currentField.name = p_CurrentObject.name;
			currentField.type = p_CurrentObject.type;
			if (!isNaN(p_maxLength)){
				currentField.maxLength = p_maxLength;	
			}else{
				currentField.maxLength = 32000;
			}					
		}
		catch (e) {
			// do nothing
			;
		}
	}

	//*******************************************************************************
	// function:	textCounter
	// description:	function to trim textarea if they exceed their max
	//*******************************************************************************
	function textCounter(field, maxlimit) {
		if (document.getElementById(field, 0).innerHTML.length > maxlimit) // if too long...trim it!
	
		document.getElementById(field, 0).innerHTML = document.getElementById(field, 0).innerHTML.substring(0, maxlimit);
	
	}

	//*******************************************************************************
	// function:	trim
	// description:	Removes leading and trailing spaces from the passed string. Also
	//				removes consecutive spaces and replaces it with one space.
	//*******************************************************************************
	function trim(inputString) {
		
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		
		while (ch == " ") { // Check for spaces at the beginning of the string
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		
		ch = retValue.substring(retValue.length-1, retValue.length);
		
		while (ch == " ") { // Check for spaces at the end of the string
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		
		return retValue; // Return the trimmed string back to the user
	} // Ends the "trim" function
	
	//*******************************************************************************
	// function:	trim2
	// description:	Removes leading and trailing spaces from the passed string. Also
	//				removes consecutive spaces and replaces it with one space. Also
	//				removes carriage returns and line feeds.
	//*******************************************************************************
	function trim2(inputString) {
		
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		
		while ((ch == " ") || (ch == "\t") || (ch == "\r") || ch == ("\n")) { // Check for spaces at the beginning of the string
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		
		ch = retValue.substring(retValue.length-1, retValue.length);
		
		while ((ch == " ") || (ch == "\t") || (ch == "\r") || ch == ("\n")) { // Check for spaces at the end of the string
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		
		return retValue; // Return the trimmed string back to the user
	} // Ends the "trim" function

	//*******************************************************************************
	// function:	initializePage
	// description:	Called from the body onload of the JSP the function does the 
	//				following:
	//				1)	brings the window to focus
	//				2)	sizes the window to 800x600 if a parameter isn't specified.
	//					Valid window paramenters are Small, Medium, or Large
	//				3)	If the closeWindow field is true it will call the 
	//					executeCloseWithPrompt JavaScript function
	//				4)	Attempt to call initTab JavaScript function on the page's
	//					js file
	//				5)	Attemp to call initPageSpecifics function on the page's
	//					js file
	//				6)	Call initializeError JavaScript function
	//				The main purpose is to set up the window		
	//*******************************************************************************
	function initializePage(p_windowSize) {
		window.focus();
		var m_object = new Object();
		m_object = window.parent;
				
		//adjusting the height and width wants a string
		
		try {
			if (m_object.name != 'ModalFrame') {
				var m_width = 800;
				var m_height = 600;
				var m_pageSize;
				
				if (!p_windowSize) {
					m_pageSize = 'LARGE';
				} else {
					m_pageSize = p_windowSize.toUpperCase();
				}
				
				if (m_pageSize == "SMALL") {
					document.getElementById('divBanner').style.backgroundImage = "url(images/flsac_small.gif)";
					top.resizeTo( 440 , 300);
				} else if (m_pageSize == "MEDIUM") {
					top.resizeTo( 640, 480);
				} else if (m_pageSize == "LARGE") {
					if (screen.availWidth > 800) {
						m_width = 800;
					} else {
						m_width = screen.availWidth;
					}
				
					if (screen.availHeight > 600) {
						m_height = 600;
					} else {
						m_height = screen.availHeight;
					}
					
					top.resizeTo( m_width, m_height);
				} else if (m_pageSize == "XLARGE") {
					if (screen.availWidth > 1024) {
						m_width = 1024;
					} else {
						m_width = screen.availWidth;
					}
				
					if (screen.availHeight > 768) {
						m_height = 768;
					} else {
						m_height = screen.availHeight;
					}
					
					top.resizeTo( m_width, m_height );
				} else {
					top.resizeTo( m_width, m_height);
				} 
			}
		} catch (e) {
				; //do nothing
		}
		
		initializeError();
					
		try {
			
			if (document.forms[0].closeWindow.value == "true") {
				executeCloseWithPrompt();
			}
			else {
				deleteSavedDocuments();
			}
		} catch (e) {
			// do nothing if exception
			;
		}
		
		// Use to initialize tabs on page
		try {
			initTab();
		} catch (e) {
			// do nothing if exception
			;
		}		
		
		// Display work area
		try {
			document.getElementById('divRetrieving').style.display = 'none';
		} catch (e) {
			// do nothing
			;//showPrompt('The JSP does not have a Retrieval prompt.', 'Close');
		}
		try {
			document.getElementById('divWorkArea').style.display = 'inline';
		} catch (e) {
			// do nothing
			showPrompt('The JSP does not have a divWorkArea.', 'Close');
		}
		
		// Use for page specific initialization
		try {
			initPageSpecifics()
		} catch (e) {
			// do nothing if exception
			;
		}
		
		sendFocusOnFirstfield();
		
	}

	//*******************************************************************************
	// function:	initializeError
	// description:	The initializeError is called from the initializePage JavaScript
	//				function.  The purpose is to see if divErrors exist on the page.
	//				If so then copy the innerHTML and show the errors in a
	//				modeless window.  The divErrors is part of the Struts framework.
	//*******************************************************************************
	function initializeError() {
		try {
			// check to see if divErrors exists to avoid errors in pages with iframes
			if (document.getElementById('divErrors')) {
				var m_arguments = new Object();
				m_arguments.m_window = window;
				m_arguments.m_divErrors = document.getElementById('divErrors').innerHTML;
				window.showModelessDialog("common/ValidationError.jsp", m_arguments ,"dialogHeight:10;status:no;help:no");
				
				// Try to reset page variables
				try {
					document.getElementById("closeWindow").value = "false";
					document.getElementById("dataChanged").value = "true";
				}
				catch (e) {
					// do nothing
				}
			}
            top.document.getElementById('linkErrors').style.visibility = 'hidden';
		} catch (e) {
			var m_object = new Object();
			m_object = window.parent;
			
			// alert user of script error
			if (m_object.name == "ModalFrame") {
				showPrompt('<u>ModalFrame initializeError exception:</u> <br/>' + e.message,"OK");
			}
			else {
				// do nothing if exception
				return;
			}
		}
	}

	//*******************************************************************************
	// function:	enableBtnErrors
	// description:	If divErrors exists, then display the Errors button on the 
	//				banner.  The function is called from the error modeless window
	//*******************************************************************************
	function enableBtnErrors() {
		if (document.getElementById('divErrors')) {
            top.document.getElementById('linkErrors').style.visibility = 'visible';
		}
	}

	//*******************************************************************************
	// function:	closePage
	// description:	Called from the body onload event.  The purpose is to alert
	//				users that changes have been made to the page and informs
	//				them how to save the data.  It checks the dataChanged field
	//				and divSaving.
	//*******************************************************************************
	function closePage(){
		try {		
			if (document.forms[0].dataChanged.value == "true" && document.getElementById('divSaving').style.display == "none") {
				window.event.returnValue = "*******************************************************\n\n\nYou have unsaved changes.\n\nPlease do one of the following:\n    1)  Click OK to close window without saving changes\n    2)  Click Cancel to go back to the window and save manually\n\n\n*******************************************************";
			}
		} catch (e) {
			// do nothing
			;
		}
	}

	//*******************************************************************************
	// function:	executeClose
	// description:	closes the pop-up window and returns control to the parent
	//*******************************************************************************
	function executeClose() {
		try{
			top.close();
			// Add code to remove the window from the list
			if(top.opener != null) {
				top.opener.focus();
			}
		} catch (e) {
			// Do Nothing
			;
		}
	}

	//*******************************************************************************
	// function:	executeCloseWithPrompt
	// description:	Call from the close button on the window.  If changes were made,
	//				the user is prompted to save changes.  The executeClosePage
	//				JavaScript function is in the individual window js file.
	//*******************************************************************************
	function executeCloseWithPrompt() {
		
		if (document.forms[0].dataChanged.value == "true") {
			var m_URL = "common/ModalPrompt.html";
			var m_args = new Object();  	
			
			if (document.getElementById('documentObject[0].documentID') != null) {
				m_args.title = "Save changes \<font color='red'\>(including documents)\</font\> before closing page?";
			}
			else {
				m_args.title = "Save changes before closing page?";
			}
			m_args.button = "YesNoCancel";	
	
			var m_returnValue = window.showModalDialog(m_URL, m_args, "dialogHeight:10;status:no;help:no");
			
			try {
				if (m_returnValue == "NO") {
					// set the dataChanged variable to false to prevent the onbeforeload from firing
					deleteDocuments();
					document.forms[0].dataChanged.value = "false";
					executeClosePage("NO");
				} else if (m_returnValue == "YES") {
					try {
						document.forms[0].closeWindow.value = "true";
					}
					catch (e) {
						// Some pages don't have the closeWindow object, so continue through function anyway.
					}
				
					// Check for confirmSave function to perform other business logic.
					// Save process will be called from confirmSave function.
					var confirmSaveExists = false;
					
					try {
						confirmSave();
						confirmSaveExists = true;
					}
					catch (e) {
						// Set flag to continue save process
						confirmSaveExists = false;
					}
					
					if (!confirmSaveExists) {
						save();
					}
				}
			} catch (e) {
				// do nothing
				;
			}
		} else {
			// Delete any saved documents from work folder.
			try {
				deleteSavedDocuments();
			}
			catch (e) {
				// do nothing
				;
			}
			
			executeClosePage();
		}
	}

	//*******************************************************************************
	// function:	testIChainTimeOut
	// description:	This call is to test iChain timeout. If it did timeout the window
	//				will show the iChain login window and only then the next line will
	//				execute. 
	//*******************************************************************************
	function testIChainTimeOut(p_MethodName){
		var m_launchIChain = false;		
		
		try {
			if (prepareDocumentSave() == false){
				resethourglass();
				return;
			}	
		} catch (e) {
			showPrompt ("Error occured while retrieving document(s) from local cache.<br/>Document(s) will not be saved.","OK");
			return;
		}
		
		if (p_MethodName == undefined){
			// Dummy method name
			callbackMethodName = "continue";
		} else {
			callbackMethodName = p_MethodName ;
		}
		
		// Call the method on the page to get the iChain window
		try {
			window.frames['timeout'].initTimeoutTest();
		} catch (e) {
			eval(callbackMethodName + "()");
		}
	}


	//*******************************************************************************
	// function:	save
	// description:	This opens the AutoClose.jsp which will tag back the method
	//				continueSave to process the save logic!!! All due to this
	//				damn iChain limitations @#@#@#$! 
	//*******************************************************************************
	function save(){
	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }
		hourglass();
		testIChainTimeOut("continueSave");
		return;
	}

	//*******************************************************************************
	// function:	continueSave
	// description:	Submits the document, and shows the save hourglass
	//*******************************************************************************
	function continueSave() {
		
		// If documents were left open in Word... do not continue
		var m_returnVal = true;
	
		try {			
			hourglass();
			m_returnVal = preprocessSave();
			if(m_returnVal == false){
				resethourglass();
				return;
			}else {
				m_returnVal = true;
			}
			
		} catch (e) {
			//
		} 
/* moved to testIChainTimeOut()
		try {
			//	display hourglass
			
			if (prepareDocumentSave() == false){
				resethourglass();
				return;
			}	
		} catch (e) {
			showPrompt ("Error occured while retrieving document(s) from local cache.<br/>Document(s) will not be saved.","OK");
			return;
		}*/
	
		try {
			document.forms[0].btnSave.disabled=true;
		} catch (e) {
			//do nothing
		}
		
		if(m_returnVal == true){
			document.forms[0].submit();
		}		
	}

	//*******************************************************************************
	// function:	hourglass
	// description:	Displays the save hourglass
	//*******************************************************************************
	function hourglass() {
		try {
			document.getElementById('divWorkArea').style.display = 'none';
		} catch (e) {
			// do nothing
			;
		}
		
		with (divSaving.style) {
			setExpression("left","document.body.clientWidth/2 - divSaving.offsetWidth/2");
			setExpression("top","document.body.clientHeight/2 - divSaving.offsetHeight/2");
			display="";
		}
	}

	//*******************************************************************************
	// function:	resethourglass
	// description:	Hides the save hourglass
	//*******************************************************************************
	function resethourglass() {
		try {
			document.getElementById('divWorkArea').style.display = 'inline';
			document.getElementById('divSaving').style.display = 'none';
		} catch (e) {
			// do nothing
			;
		}	
		
	}
	
	//*******************************************************************************
	// function:	searchHourglass
	// description:	Displays the search hourglass
	//*******************************************************************************
	function searchHourglass() {
		try {
			document.getElementById('divWorkArea').style.display = 'none';
		} catch (e) {
			// do nothing
			;
		}
		
		with (divSearching.style) {
			setExpression("left","document.body.clientWidth/2 - divSearching.offsetWidth/2");
			setExpression("top","document.body.clientHeight/2 - divSearching.offsetHeight/2");
			display="";
		}
	}

	//*******************************************************************************
	// function:	changes
	// description:	Sets the dataChanged field to true and enables the Save button.
	//*******************************************************************************
	function changes() {
		try {
			document.forms[0].dataChanged.value = "true";
			document.forms[0].btnSave.disabled=false;
		} catch (e) {
			// do nothing
			;
		}
	}

	var helpWindow;
	//*******************************************************************************
	// function:	launchHelp
	// description:	Takes the p_jspName which is the same name as the window title, replaces spaces
	// with _, and launches the associated HTML help file from RoboHelp.
	//*******************************************************************************
	function launchHelp(p_jspName) {

		var launchHelp = false;
		
		if (helpWindow == undefined){
			launchHelp = true;
		} else if ( helpWindow.closed == true) {
			launchHelp = true;
		}
				
		if (launchHelp)	{
			//Added this condition to support launching the Help files.
			if ((p_jspName != null) && (p_jspName.substr(0, 17) == "Person Management")){
				p_jspName = "Person Management";
			}
			// Added below conidtions to fix Incident 3242.
			if ((p_jspName != null) && (p_jspName.substr(0, 16) == "Child Assessment")){
				p_jspName = "Child Assessment";
			}
			if ((p_jspName != null) && (p_jspName.substr(0, 16) == "Adult Assessment")){
				p_jspName = "Adult Assessment";
			}
			
			if ((p_jspName != null) && (p_jspName.substr(0, 22) == "Copy Family Assessment")){
				p_jspName = "Copy Family Assessment";
			}
					
			helpWindow = window.showModelessDialog(contextRoot + "cm/cm12/webhelp/fsfn_help/" + p_jspName.replace(/ /g,'_') + ".htm",null ,"dialogHeight:480px;dialogWidth:640px;dialogTop:0;dialogLeft:0;status:no;help:no;");
		} else {
			helpWindow.focus();
		}
	
	}

	//*******************************************************************************
	// function:	printPage
	// description:	
	//*******************************************************************************	
	function printPage() {	
		window.print();	
	}
	
	//*******************************************************************************
	// function:	window.onbeforeprint
	// description:	
	//*******************************************************************************
	function window.onbeforeprint()
	{
	    try {
			if (window.name == 'ModalFrame'){
				window.frames['jspFrame'].document.getElementById("divWorkArea").style.overflow="visible";
			} else {
				document.getElementById("divWorkArea").style.overflow="visible";
			}
		} catch (e) {
			// Do nothing
			;
	  	}

		try {
			// Call methods in individual windows to expand print regions if any
			expandPrintRegions();
		} catch (e) {
			// Do nothing
			;
	  	}
	}
	
	//*******************************************************************************
	// function:	window.onafterprint
	// description:	
	//*******************************************************************************
	function window.onafterprint()
	{
	   try {
			if (window.name == 'ModalFrame'){
				window.frames['jspFrame'].document.getElementById("divWorkArea").style.overflow="auto";
			} else {
				document.getElementById("divWorkArea").style.overflow="auto";
			}
		} catch (e) {
			// Do nothing
			;
	  	}

		try {
			// Call methods in individual windows to collapse print regions if any
			collapsePrintRegions();
		} catch (e) {
			// Do nothing
			;
	  	}
	}


	//*******************************************************************************
	// function:	launchModal
	// description:	Opens a modal dialog window.  The argument is the URL.
	//*******************************************************************************
	function launchModal(p_arguments){
	   try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }
		return window.showModalDialog('common/ModalFrame.jsp', p_arguments, 'dialogLeft:0;dialogTop:0;status:no;help:no;scroll:no;');
	}

	//*******************************************************************************
	// function:	appWindow
	// description:	
	//*******************************************************************************
	function appWindow(pUrl, pWindowObj){
		this.url = pUrl;
		this.window = pWindowObj;
	}

	//*******************************************************************************
	// function:	addToWindowList
	// description:	
	//*******************************************************************************
	function addToWindowList(pUrl , pWindow){
		// See if the url already exists in the list and if so then update
		windowList[windowList.length] = new appWindow (getBaseUrl(pUrl) , pWindow);
	}

	//*******************************************************************************
	// function:	getIndexOfWindow
	// description:	Check to see if the window is already open.  For the Create Case
	//				and Provider Work windows, need to check if those windows are open
	//				or the new piece of work.
	//*******************************************************************************
	function getIndexOfWindow(p_Url){
		
		var m_localUrl = getBaseUrl(p_Url);
		
		// Loop through the array to see if the window is already open
		var m_length = windowList.length;

		for (var i = 0; i < m_length; i++) {
			try{																			
				if ((!windowList[i].window.closed) && (windowList[i].url.indexOf(m_localUrl) != -1)) {
					
					if ((m_localUrl.indexOf('SM04B_CreateCaseWork') != -1) || (m_localUrl.indexOf('SM04B_CreateProviderWork') != -1) 
								|| (m_localUrl.indexOf('SM04B_CreateFinancialWork') != -1)) {
					
						 if (windowList[i].window.document.URL.indexOf(m_localUrl) == -1 ) {
						 	continue;
						 }						
					}
					return i;
				}
			} catch (e) {
				// Do nothing
				;
			}
		}
		
		return -1;
	}

	//*******************************************************************************
	// function:	getBaseUrl
	// description:	
	//*******************************************************************************
	function getBaseUrl(pUrl){
		// Save detailed URL information
		return pUrl;
	/*
		// Commented since once create case work is launched, it does a submit on the same window
		// to be able to track which window is open, we have to keep a log of the entire url
		// and check with the window.URL to determine if it's open. This will also fulfill a requirement
		// that a user can open multiple windows but not for the same data.
		var actualUrl;
		var i;
		
		i = pUrl.search (".do");
		if ( i > 0 ){
			actualUrl = pUrl.substr ( 0 , i + 3);
		} else {
			actualUrl = pUrl;
		}
		return actualUrl;
	*/
	}

	//*******************************************************************************
	// function:	createWindow
	// description:	
	//*******************************************************************************
	function createWindow(pUrl,pScroll){
	
		if (pScroll == undefined || pScroll == null) {
			pScroll = "no"
		}
		
		aWindowOpen = true;
		
		return window.open(pUrl,"_blank","left=0,top=0,titlebar=no,menubar=no,scrollbars="+pScroll+",status=yes,resizable=yes");
	
	}

	//*******************************************************************************
	// function:	launchWindow
	// description:	
	//*******************************************************************************
	function launchWindow(pUrl,pScroll){
		var i;
		var m_window;
		i = getIndexOfWindow(pUrl);

	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }
	
		if (i == -1 )  {
			if (pUrl.indexOf("optimistic=true") > -1 ) {
				m_window = createWindow_OPT(pUrl, pScroll);
			} else {
				m_window = createWindow(pUrl, pScroll);
			}
			addToWindowList(pUrl , m_window );
		} else {
			if ( windowList[i].window.closed == false ) {
				// If window was previously opened but was closed then
				showPrompt (windowList[i].window.document.title + " is already open.<br/>Please complete the current work.","OK");
			} else {
				if (pUrl.indexOf("optimistic=true") > -1 ) {
					windowList[i].window = createWindow_OPT(pUrl);
				} else {
					windowList[i].window = createWindow (pUrl);
				}
			}
		}
		if(i != -1)
			windowList[i].window.focus();
			
		if (m_window != undefined){
			try{
				m_window.focus();
			} catch (e) {
				// Do Nothing
				;
			}
		}
	}

	function isAnyWindowOpen(){

		if (aWindowOpen){
			var j;
	
			j=windowList.length;
		
			for (i=0;i<j;i++){
				if (windowList[i].window.closed == false){
					showPrompt (windowList[i].window.document.title + " is still open.<br/>Please complete the current work before logging out.","OK");
					windowList[i].window.focus();
					return true;
				}
			}
		} 

		return false;
		
	}
	
	//*******************************************************************************
	// function:	launchLink
	// description:	
	//*******************************************************************************
	function launchLink(pUrl){
	
	//	do not use this function to link to sacwis pages!
	
	
	//  this function will launch an independent window, such as a link to the knowledge center or a link to 
	//  a county web site.  
	
	
		window.open(pUrl,"_blank","left=0,top=0,toolbar=yes,titlebar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,location=yes");
	}

	//*******************************************************************************
	// function:	docList
	// description:	
	//*******************************************************************************
	function docList(p_action, p_docID, p_isDocument , p_readOnly , p_templateID,p_idWrkType){
		this.action = p_action;
		this.docID = p_docID;
		this.isDocument = p_isDocument;
		this.readOnly = p_readOnly;
		this.templateID = p_templateID;
		this.idWrkType = p_idWrkType;
	}

	//*******************************************************************************
	// function:	addToDocList
	// description:	
	//*******************************************************************************
	function addToDocList(p_action, p_docID, p_isDocument , p_readOnly , p_templateID, p_idWrkType){
		// See if the url already exists in the list and if so then update
		documentList[documentList.length] = new docList (p_action, p_docID, p_isDocument , p_readOnly , p_templateID, p_idWrkType);
	}

	//*******************************************************************************
	// function:	getIndexOfDocument
	// description:	
	//*******************************************************************************
	function getIndexOfDocument(p_action){
		// Loop through the array to see if the window is already open
		j = documentList.length;
		for (i=0;i<j;i++){
			if (documentList[i].action == p_action)
				return i;
		}
		return -1;
	}

	//*******************************************************************************
	// function:	getIndexOfDocumentByidWrkType
	// description:	
	//*******************************************************************************
	function getIndexOfDocumentByidWrkType(p_idWrkType){
		// Loop through the array to see if the window is already open
		var m_type = document.getElementById("idWorkType").value;
		var m_array = new Array();
		
		if (m_type != '' || m_type != null && m_type.length > 0) 
			m_array = m_type.split(',');
				
		j = m_array.length;
		for (i=0;i<j;i++){
			if (m_array[i] == p_idWrkType)
				return i;
		}
		return -1;
	}

	//*******************************************************************************
	// function:	LaunchDocument
	// description:	
	//*******************************************************************************
	function launchDocument(pParameter){
		var m_returnVal , m_DocIndex, m_array ; 
	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }
		
		documentFormData = pParameter;
	
		if (pParameter.idWrkType == undefined) {
			documentFormData.idWrkType = null;
			m_DocIndex = getIndexOfDocument(documentFormData.documentAction);
			
			if ( m_DocIndex != -1 )
				documentFormData.docID = documentList[m_DocIndex].docID;
		} else {
			m_DocIndex = getIndexOfDocumentByidWrkType(documentFormData.idWrkType);
			
			if ( m_DocIndex != -1 ) {
				m_array = document.getElementById("documentID").value.split(',');
				documentFormData.docID = m_array[m_DocIndex];				
			}
		}	
		
		m_returnVal = window.showModalDialog( contextRoot + "eforms/DocumentToolBar.jsp",  documentFormData ,"dialogWidth:305px;dialogHeight:136px;status:no;help:no;scroll:no");
	
		if (m_returnVal != undefined && m_DocIndex == -1 ) {
			addDocIdToLocal(m_returnVal);
			addToDocList(documentFormData.documentAction, m_returnVal, documentFormData.isDocument, documentFormData.readOnly , documentFormData.templateID,documentFormData.idWrkType);
		}
	
		return m_returnVal;
	}
	
	function addDocIdToLocal(p_docID) {
		var m_array, m_loop=0, m_found=false;
		var m_list;
		
		try {
			m_list = document.getElementById("documentID").value;
			
			if (m_list != '' && m_list != null && m_list.length > 0) {
				m_array = m_list.split(',');
				
				for(m_loop=0; m_loop < m_array.length; m_loop++) {
					if (m_array[m_loop] == p_docID) {
						m_found=true;
						break;
					}
				}
				
				if (m_found != true) document.getElementById("documentID").value += ','+p_docID;
			} else {
				document.getElementById("documentID").value = p_docID;
			}	
		
		} catch(e) {
			//
		}
	}

	//*******************************************************************************
	// function:	deleteDocuments
	// description:	
	//*******************************************************************************
	function deleteDocuments(){
		if (documentList == null)
			return true;
	
		var m_returnValue;
	
		try{
			j = documentList.length;
			for (i=0;i<j;i++){
				m_returnValue = window.showModalDialog(contextRoot + "eforms/DocumentDelete.jsp" , documentList[i].docID , "dialogWidth:305px;dialogHeight:100px;status:no;help:no;scroll:no");
			}
			//documentList = null;
			// Do not need to set documentList to null.
			// Will skip processing in for loop because length will be zero. (kdd)
			documentList = new Array();
			return;	
		} catch (e){
			showPrompt(e.message,"OK");
			return;
		}
	
	}
	
	//*******************************************************************************
	// function:	deleteSavedDocuments
	// description:	
	//*******************************************************************************
	function deleteSavedDocuments() {
		
		var counter = 0;
		var m_next = true;
		var m_noErrors = true;
		var m_returnValue;
		var m_textObj;
		var m_textValue;
		var m_id;
		var m_index = -1;
		
		try {
			
			// Check for at least one documentObject.
			if (document.getElementById('documentObject[0].documentText') == null) {
				return;
			}
			
			// Check for any validation errors
			if (document.getElementById('divErrors')) {
				m_noErrors = false;
			}
			
			// Loop through documentObject array.
			while (m_next) {
				
				m_textObj = document.getElementById('documentObject[' + counter + '].documentText');
				
				if (m_textObj != null) {
				
					m_textValue = m_textObj.innerHTML;
				
					if ((m_textValue != null)  && (m_textValue != "")) {
						
						// Check for SAVED indicator
						m_index = m_textValue.indexOf("||SAVED||");
						
						if (m_index != -1) {
						
							// If validation errors don't exist, parse for ID_DOC_TEXT
							if (m_noErrors) {
							
								m_id = m_textValue.slice(m_index + 9);
								
								if (m_id.length > 0) {
								
									m_id = trim2(m_id);
								
									// Use OCX to delete document.
									m_returnValue = window.showModalDialog(
											contextRoot + 
											"eforms/DocumentDelete.jsp", 
											m_id, 
											"dialogWidth:305px;dialogHeight:100px;status:no;help:no;scroll:no");
								}
							}
							
							// Reset variables
							m_textObj.innerHTML = "";
							m_index = -1;
						}
					} // End If check innerHTML for null or ""
					
					counter++;
				}
				else {
					// Set flag to exit loop
					m_next = false;
				}
			} // End While
		}
		catch (e) {
			alert("deleteSavedDocuments exception: " + e.message);
		}	
	}

	//*******************************************************************************
	// function:	prepareDocumentSave
	// description:	
	//*******************************************************************************
	function prepareDocumentSave(){
		var m_returnValue;
		if (documentList == null)
			return true;
		try{
			j = documentList.length;
			for (i=0;i<j;i++){
					
				m_returnValue = window.showModalDialog(contextRoot + "eforms/DocumentSave.jsp" , documentList[i] , "dialogWidth:305px;dialogHeight:100px;status:no;help:no;scroll:no");
				if (m_returnValue == "ERROR"){
					showPrompt ("Document <u>" + documentList[i].docID + ".0.rtf</u> is open.<br/>Please close the document in Word before proceeding." , "OK");
					return false;
				}
				if (documentList[i].readOnly == false && m_returnValue != ""){
					document.getElementById(documentList[i].templateID).value = m_returnValue;
				} 
			}
			//documentList = null;
			// Do not need to set documentList to null.
			// Will skip processing in for loop because length will be zero. (kdd)
			documentList = new Array();
			
			return true;	
		} catch (e){
			showPrompt (e.message , "OK");
			return false;
		}
	}

	//*******************************************************************************
	// function:	showPrompt
	// description:	Generic function to show all modal prompts.  Returns
	//				whatever is the modal window currently returns.
	//				Valid button type parameters:
	//				1)	YesNoCancel
	//				2)	YesNo
	//				3)	Close
	//*******************************************************************************
	function showPrompt(p_Title, p_ButtonType)
	{
	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }

		var m_args = new Object();  	
		var m_URL = contextRoot + "common/ModalPrompt.html";
			
		m_args.title = p_Title;
		m_args.button = p_ButtonType;	
	
		var m_returnValue = window.showModalDialog(m_URL, m_args, "dialogHeight:12;status:no;help:no");
	
		return m_returnValue;
	}
	
	//*******************************************************************************
	// function:	spellCheck
	// description:	
	//*******************************************************************************
	function spellCheck(){
	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }

		if (currentField.name == null || currentField.name == undefined){
			return;
		}
		
		var m_TextArea, m_dataType, m_maxLength;
		m_TextArea = currentField.name;
		m_dataType = currentField.type;
		m_maxLength = currentField.maxLength;
		
		try {
		 
	    	if (document.getElementById(m_TextArea).readOnly){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }
	    
		var m_newText,m_oldText;
	
		if ( m_dataType == "textarea" ) {
			m_oldText = document.getElementById(m_TextArea).innerText;
		} else if (m_dataType == "text") {
			m_oldText = document.getElementById(m_TextArea).value;
		} else {
			return;
		}
	
		if (m_oldText == "") {
			// Do nothing
			return;
		}
	
		m_newText = window.showModalDialog(contextRoot + "eforms/DocumentSpellcheck.jsp" , document.getElementById(m_TextArea) , "dialogWidth:305px;dialogHeight:100px;status:no;help:no;scroll:no");
	
		if ( m_newText == "" || m_newText == undefined){
			// Do Nothing
			//alert ("Nothing to Spell Check");
			return;
		}
	
		if (m_newText == m_oldText){
			//alert ("Spell Check Complete");
		}
		
		// Incident #3726. Do not return a greater number of characters than the maxlength of the field.
		if ((m_maxLength > 0) && (m_newText.length > m_maxLength)) {
			m_newText = m_newText.substr(0, m_maxLength);
		}
		
		if ( m_dataType == "textarea" ) {
		    m_newText = prepareString(m_newText);
			document.getElementById(m_TextArea).innerText = m_newText;
			document.getElementById(m_TextArea).fireEvent('onKeyUp');
			changes();
		} else if (m_dataType == "text") {
		    m_newText = prepareString(m_newText);
			document.getElementById(m_TextArea).value = m_newText;
			changes();
		} else {
			return;
		}
		
		showPrompt("The spell check is complete.", "Close");
	}
	
	//*******************************************************************************
	// function:	penWrite - used for Tablet pen input
	// description:	
	//*******************************************************************************
	function penWrite(argumentField){
	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }

		if (argumentField != undefined){
			currentField.name = argumentField.name;
			currentField.type = argumentField.type;
		}

		if (currentField.name == null || currentField.name == undefined){
			return;
		}
		
		var m_TextArea, m_dataType;
		m_TextArea = currentField.name;
		m_dataType = currentField.type;
	
		var m_newText,m_oldText;
		var m_parm = new Object();

		if (document.getElementById(m_TextArea).disabled == "true")
			return;
				

		if ( m_dataType == "textarea" ) {
			m_oldText = document.getElementById(m_TextArea).innerText;
			m_parm.multiline = true;
			m_parm.maxlength = 0;
		} else if (m_dataType == "text") {
			m_oldText = document.getElementById(m_TextArea).value;
			m_parm.multiline = false;
			m_parm.maxlength = document.getElementById(m_TextArea).maxLength;
		} else {
			return;
		}

		if (m_oldText == "") {
			// Do nothing
			m_oldText == " ";
		}

		m_parm.text = m_oldText;
		
		m_newText = window.showModalDialog(contextRoot + "eforms/DocumentInkWrite.jsp" , m_parm , "dialogWidth:305px;dialogHeight:100px;status:no;help:no;scroll:no");
	
		if ( m_newText == "" || m_newText == undefined){
			// Do Nothing
			//alert ("Nothing to Spell Check");
			return;
		}
	
		if (m_newText == m_oldText){
			//alert ("Spell Check Complete");
		}
		if ( m_dataType == "textarea" ) {
		    document.getElementById(m_TextArea).innerText = m_newText;
			changes();
		} else if (m_dataType == "text") {
			document.getElementById(m_TextArea).value = m_newText;
			changes();
		} else {
			return;
		}
	
	}

	//*******************************************************************************
	// function:	SaveAsExcel
	// description:	
	//*******************************************************************************
	function saveAsExcel(pForm, pAction){
	    try {
	    	if (failedValidation){
		   		return;
	   		}
	    } catch (e) {
	    	// Do nothing since there is no validation on this page
	    	;
	    }
		var mParameter = new Object();

		mParameter.formName = pForm;
		mParameter.formAction = pAction;

		// Launch the Save As dialog box
		window.showModalDialog( contextRoot + "eforms/ExcelToolBar.jsp",  mParameter ,"dialogWidth:370px;dialogHeight:150px;status:no;help:no;scroll:no");

		return;
	}
	
	//*******************************************************************************
	// function:	viewSource
	// description:	To be able to view source from anywhere in the app
	//*******************************************************************************
	function viewSource(pObjectType, pObject){
		var pParameter = new Object();
		pParameter.ObjectType = pObjectType;
		pParameter.ObjectBody = pObject;
		
		window.showModelessDialog(contextRoot + "common/ViewSource.jsp"
		    ,pParameter 
		    ,"resizable:yes; unadorned:yes; status: yes; dialogWidth:640px; dialogHeight:700px;");
	}
	
	//*******************************************************************************
	// function:	initializeLogon
	// description:	This was added because we don't want to run all the initialize scripts
	// 				used for other windows when using the logon window most notably, not
	//				shrinking the screen size but still initializing security.
	//*******************************************************************************
	function initializeLogon() {
		window.focus();
		initializeError();
	}
	
	
	//*******************************************************************************
	// function:	prepareString
	// description:	This function removes the character (? ? ? ?) from a given string and
	// replaces it with (' ' " ") characters. also replaces elongated dash with regular dash
	//*******************************************************************************
	function prepareString(p_string){
		var myString = p_string;
//		myString = p_string.replace(/?/g,"'");
//		myString = myString.replace(/?/g,"'");
//		myString = myString.replace(/\?/g,"\"" );
//		myString = myString.replace(/\?/g,"\"" );
		
		myString = compressMultipleWhiteSpace(myString);
		
		return myString;
	}
	
	//*******************************************************************************
	// function:	prepareTextAreaString
	// description:	This function checks for the maxlength andremoves the character (? ? ? ?) from a 
	// given string and replaces it with (' ' " ") characters. also replaces elongated dash with regular dash.
	//*******************************************************************************
	function prepareTextAreaString(p_string,maxlength){
		
		if (p_string.length > maxlength) // if too long...trim it!
		p_string = p_string.substring(0, maxlength);
		var myString = p_string;
//		myString = p_string.replace(/?/g,"'");
//		myString = myString.replace(/?/g,"'");
//		myString = myString.replace(/\?/g,"\"" );
//		myString = myString.replace(/\?/g,"\"" );
		
		myString = compressMultipleWhiteSpace(myString);
		return myString;
	}
	
	//********************************************************************************
	//	OPTIMIZATION TEST AREA
	//********************************************************************************
	
	//*******************************************************************************
	// function:	createWindow
	// description:	
	//*******************************************************************************
	function createWindow_OPT(pUrl,pScroll){
	
		if (pScroll == undefined || pScroll == null) {
			pScroll = "no"
		}
		WindowArguments.m_URL = pUrl;
		return window.open(contextRoot + "common/ContainerFrame_OPT.jsp" + "?page=UnmetNeeds","_blank","left=0,top=0,titlebar=no,menubar=no,scrollbars="+pScroll+",status=yes,resizable=yes");
	
	}

	//*******************************************************************************
	// function:	compressMultipleWhiteSpace. This function will replace one or more white spaces with a single 
	//				white space.
	// description:	
	//*******************************************************************************
	function compressMultipleWhiteSpace(value) {
	   var temp = value;
	   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
	   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
	   var obj = / +/g;
	   temp = temp.replace(obj, " ");
	   if (temp == " ") { temp = ""; }
	   return temp.replace(/^\s*|\s*$/g,"");
	}

	//*******************************************************************************
	// function:	cleanTempDocumentDir. 			
	// description:	This function will clean out all the rtf douments in the temporary work directory.
	//*******************************************************************************
	function cleanTempDocumentDir(){
		try{
			var m_fsfnDir = "C:\\FSFN\\work";
			var m_dirLocalSystem = new ActiveXObject("Scripting.FileSystemObject");
			if ( m_dirLocalSystem.FolderExists(m_fsfnDir) ){
				var m_objFolder = m_dirLocalSystem.GetFolder(m_fsfnDir);
				var m_fileEnum = new Enumerator(m_objFolder.Files);
				for ( i=0; !m_fileEnum.atEnd(); m_fileEnum.moveNext() ){
					var m_file = m_dirLocalSystem.GetFile(m_fsfnDir + "\\" + m_fileEnum.item().name);
					m_file.Delete(true);
				}		
			}
		}catch(e){
		}
	}
	
	//*******************************************************************************
	// function:	showAudit
	// description:	
	//*******************************************************************************	
	function showAudit(){
		try {
			// Call methods in individual windows to expand print regions if any
			processAudit();
		} catch (e) {
	       var m_URL = "common/ModalPrompt.html";
		   var m_args = new Object();  	
		   m_args.title = "No Audit Information is available for this page.";
		   m_args.button = "OK";	
		   var m_returnValue = window.showModalDialog(contextRoot + m_URL, m_args, "dialogHeight:10;status:no;help:no");                                  
	  	}
	}
	//*******************************************************************************
	// function:	launchAuditWindow
	// description:
	//*******************************************************************************
	function launchAuditWindow(theFrom,id_wrk_type){
		var m_returnValue = new Object();
		var m_arguments = new Object();
		var theDestination = "CM09_AuditInformation";
		var theParameters = "&ID_WRK_TYPE=" + id_wrk_type ;
		m_arguments.m_URL = contextRoot 
			+ theDestination 
			+ '.do?action=OPEN&fromWhere='
			+ theFrom
			+ theParameters;
		m_arguments.m_title = "Audit Information";
		m_arguments.m_pageSize = "Large";			
		m_returnValue = launchModal(m_arguments);
	}
	
	//
	//*******************************************************************************
	// function:	validateAddress
	// description: Validates the User entered Address with the Code1 System.
	//*******************************************************************************
	
	function validateAddress(theFrom, stNbr, stNme, unitDesg, txtUntDesg, bldNbr, poBox, rtType, rtNbr, rtBxNbr, city, cnty, state, zip, cntry) {
		var m_arguments = new Object();
		m_arguments.m_title = 'Address Normalization';
		var theDestination = "IN04_AddressConfirmation";
		var theParameters = "&ADDRESS_AD_STRT_NBR=" + stNbr 
			+ "&ADDRESS_AD_STRT_NME=" + stNme
			+ "&ADDRESS_CD_UNIT_DSGNT=" + unitDesg
			+ "&ADDRESS_TX_UNIT_DSGNT=" + txtUntDesg
			+ "&ADDRESS_AD_BLGN=" + bldNbr
			+ "&ADDRESS_AD_POBOX=" + poBox
			+ "&ADDRESS_CD_ROUTE_TYPE=" + rtType
			+ "&ADDRESS_AD_ROUTE_NMBR=" + rtNbr
			+ "&ADDRESS_AD_ROUTE_BOXNMBR=" + rtBxNbr
			+ "&ADDRESS_TX_TOWN=" + city
			+ "&ADDRESS_CD_CNTY=" + cnty
			+ "&ADDRESS_CD_STATE=" + state
			+ "&ADDRESS_CD_ZIP=" + zip
			+ "&ADDRESS_CD_CNTRY=" + cntry
			;
		m_arguments.m_URL = contextRoot 
			+ theDestination 
			+ '.do?action=VIEW&fromWhere='
			+ theFrom
			+ theParameters;
		m_arguments.m_pageSize = 'medium';
		m_returnValue = launchModal(m_arguments);	
		return m_returnValue;
	}